package com.yuyou.train.util.tool;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class HtmlUtils {

	
	/**
	  * 删除所有的HTML标签
	  *
	  * @param source 需要进行除HTML的文本
	  * @return
	  */
	public static String deleteAllHTMLTag(String source) {

	  if(source == null) {
	       return "";
	  }

	  String s = source;
	  /** 删除普通标签  */
	  s = s.replaceAll("<(S*?)[^>]*>.*?|<.*? />", "");
	  /** 删除转义字符 */
	  s = s.replaceAll("&.{2,6}?;", "");
	  /** 删除换行符 */
	  s = replaceBlank(s);
	  return s;
	}
	
	/**
	 * 
	 * 	注：\n 回车(\u000a) 
		\t 水平制表符(\u0009) 
		\s 空格(\u0008) 
		\r 换行(\u000d)
	 * 
	 */
	public static String replaceBlank(String str) {
		String dest = "";
		if (str!=null) {
			Pattern p = Pattern.compile("\t|\r|\n");
			Matcher m = p.matcher(str);
			dest = m.replaceAll("");
		}
		return dest;
	}
	
	public static void main(String[] args) {
//		String c="<p>已知函数<img class=\"latex\" src=\"http://trp.yuyou100.com/equation?preview=true&tex=f(x)%3D%5Cfrac1%7B2%5Ex-1%7D%2B%5Cfrac12\" data-latex=\"f(x)=\\frac1{2^x-1}+\\frac12\"/></p><p>（1）讨论<img class=\"latex\" src=\"http://trp.yuyou100.com/equation?preview=true&tex=f(x)\" data-latex=\"f(x)\"/>的奇偶性；</p><p>（2）求函数<img class=\"latex\" src=\"http://trp.yuyou100.com/equation?preview=true&tex=f(x)\" data-latex=\"f(x)\"/>的值域.</p>";
//		String cc=deleteAllHTMLTag(c);
//		System.out.println(cc);
//		
//		String ccc="<p>test<img class=\"latex\" src=\"http://latex.yuyou100.com/equation?tex=%5Csqrt%7Ba%7D\" data-latex=\"\\sqrt{a}\"/></p>";
//		String cccc=deleteAllHTMLTag(ccc);
//		System.out.println(cccc);
		
		String a="<p>下列有关化学用语使用正确的是（&nbsp;&nbsp;&nbsp;&nbsp;）</p><ol class=\" list-paddingleft-2\" style=\"list-style-type: upper-alpha;\"><li><p>&nbsp;<img class=\"latex\" src=\"http://latex.yuyou100.com/equation?tex=%5Cce%7BS%5E2-%7D\" data-latex=\"\\ce{S^2-}\"/>&nbsp;的结构示意图：<img src=\"http://static.yuyou100.com/Foar7yrTgl9w2NhGodDgWBBVmakx\" title=\"\" alt=\"image.png\" width=\"93\" height=\"50\" style=\"width: 93px; height: 50px;\"/></p></li><li><p>&nbsp;<img class=\"latex\" src=\"http://latex.yuyou100.com/equation?tex=%5Cce%7BNaCl%7D\" data-latex=\"\\ce{NaCl}\"/> 的形成：<img src=\"http://static.yuyou100.com/FoRwQwOzJGUL-QslrEBnkqoL0s93\" title=\"\" alt=\"image.png\"/></p></li><li><p>氕原子的符号：<img class=\"latex\" src=\"http://latex.yuyou100.com/equation?tex=%5Cce%7B%5E%7B2%7D_%7B1%7DH%7D\" data-latex=\"\\ce{^{2}_{1}H}\"/></p></li><li><p>&nbsp;<img class=\"latex\" src=\"http://latex.yuyou100.com/equation?tex=%5Cce%7BHCl%7D\" data-latex=\"\\ce{HCl}\"/> 的电子式：<img class=\"latex\" src=\"http://latex.yuyou100.com/equation?tex=%7B%5Cce%7BH%2B%7D%7D%20%20%7B%5Cspace%7D%20%20%5B%20%7B%5Cspace%7D%20%20_%5Cbullet%5E%5Ctimes%20%20%7B%5Cspace%7D%20%20%7B%5Cunderset%7B%5Cbullet%5Cbullet%7D%20%20%7B%5Coverset%7B%5Cbullet%5Cbullet%7D%20%20%7B%5Cce%7BCl%7D%7D%20%20%7D%7D%20%20%20%7B%7B%5Cspace%7D_%5Cbullet%5E%5Cbullet%7B%5Cspace%7D%7D%20%5D%5E%7B-%7D\" data-latex=\"{\\ce{H+}}  {\\space}  [ {\\space}  _\\bullet^\\times  {\\space}  {\\underset{\\bullet\\bullet}  {\\overset{\\bullet\\bullet}  {\\ce{Cl}}  }}   {{\\space}_\\bullet^\\bullet{\\space}} ]^{-}\"/></p>";
//		
//		String aa=deleteAllHTMLTag(a);
//		System.out.println(aa);
		
//		String b="You were the shadow to my light Did you feel us?\r\n" + 
//				"\r\n" + 
//				"\r\n" + 
//				"\r\n" + 
//				"​";
		String bb=deleteAllHTMLTag(a);
		System.out.println(bb);
		
		
	}
	
	
}
